﻿@model ESN.Models.Group
<h2>@ViewBag.Title</h2>

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $("#Groups").accordion({
            autoHeight: false,
            navigation: true
        });
        $(".wallPermissionCheckbox").change(function () {
            var f = 0;
            var u = 0;
            var g = 0;

            if ($("#frw").is(":checked"))
                f = f + 1;
            if ($("#fpw").is(":checked"))
                f = f + 2;

            if ($("#urw").is(":checked"))
                u = u + 1;
            if ($("#upw").is(":checked"))
                u = u + 2;

            if ($("#grw").is(":checked"))
                g = g + 1;

            $("form").valid();
            $("#WallPermission").val(f.toString() + u.toString() + g.toString());
        });
    });
</script>
<div id="Groups">
    <h3><a href="#">@ViewBag.GroupJoin</a></h3>
    <div id="JoinGroup">
    <table border="1">
        <tr>
            <th>@ViewBag.GroupName</th>
            <th>@ViewBag.GroupDes</th>
        </tr>
        @if (ViewBag.JoinGroups != null)
        {
            foreach (var g in ViewBag.JoinGroups)
            {
                <tr>
                    <td><a href="/Group/Home/@g.GId">@g.GName</a></td>
                    <td>@g.GDescription</td>
                </tr>
            }
        }
    </table>
    </div>
    <h3><a href="#">@ViewBag.GroupOwn</a></h3>
    <div id="OwnGroup">
    <table border="1">
        <tr>
            <th>@ViewBag.GroupName</th>
            <th>@ViewBag.GroupDes</th>
            <th>@ViewBag.GroupPermission</th>
            <th>Yêu cầu tham gia</th>
        </tr>
        @if (ViewBag.OwnGroups != null)
        {
            foreach (var g in ViewBag.OwnGroups)
            {
                <tr>
                    <td><a href="/Group/Home/@g.GId">@g.GName</a></td>
                    <td>@g.GDescription</td>
                    <td>
                        @if (g.GPermission == 0)
                        {
                            <span>@ViewBag.GroupPermissionInvite</span>
                        }
                        else if (g.GPermission == 1)
                        {
                            <span>@ViewBag.GroupPermissioRequest</span>
                        }
                        else if (g.GPermission == 2)
                        {
                            <span>@ViewBag.GroupPermissionFree</span>   
                        }
                    </td>
                    <td><a href="/Group/Request/@g.GId">@g.GroupRequests.Count</a></td>
                </tr>
            }
        }
    </table>
    </div>
    <h3><a href="#">@ViewBag.GroupCreate</a></h3>
    <div>
        @using (Html.BeginForm())
        {
            @Html.ValidationSummary(true)
            <fieldset>
                <div class="editor-label">
                    @ViewBag.GroupName
                </div>
                <div class="editor-field">
                    @Html.EditorFor(model => model.GName)
                    @Html.ValidationMessageFor(model => model.GName)
                </div>

                <div class="editor-label">
                    @ViewBag.GroupDes
                </div>
                <div class="editor-field">
                    @Html.EditorFor(model => model.GDescription)
                    @Html.ValidationMessageFor(model => model.GDescription)
                </div>

                <div class="editor-label">
                    @ViewBag.GroupPermission
                </div>
                <div class="editor-field">
                    <table>
                        <tr>
                            <td>@ViewBag.GroupPermissionInvite</td>
                            <td>@ViewBag.GroupPermissioRequest</td>
                            <td>@ViewBag.GroupPermissionFree</td>
                        </tr>
                        <tr>
                            <td>@Html.RadioButtonFor(model => model.GPermission, 0)</td>
                            <td>@Html.RadioButtonFor(model => model.GPermission, 1)</td>
                            <td>@Html.RadioButtonFor(model => model.GPermission, 2)</td>
                        </tr>
                    </table>
                    @Html.ValidationMessageFor(model => model.GPermission)
                </div>


                <div class="editor-field">
                    <input id="OwnerId" name="OwnerId"  type="hidden" value="@ViewBag.UserId" />
                </div>

                <div class="editor-label">
                    @Html.LabelFor(model => model.WallPermission)
                </div>
                <div class="editor-field">
                    <table style="text-align:center;">
                        <thead>
                            <tr>
                                <th></th>
                                <th>@ViewBag.Read</th>
                                <th>@ViewBag.Post</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>@ViewBag.Member</td>
                                <td><input id="frw" type="checkbox" class="wallPermissionCheckbox" /></td>
                                <td><input id="fpw" type="checkbox" class="wallPermissionCheckbox" /></td>
                            </tr>
                            <tr>
                                <td>@ViewBag.User</td>
                                <td><input id="urw" type="checkbox" class="wallPermissionCheckbox" /></td>
                                <td><input id="upw" type="checkbox" class="wallPermissionCheckbox" /></td>
                            </tr>
                            <tr>
                                <td>@ViewBag.Guest</td>
                                <td><input id="grw" type="checkbox" class="wallPermissionCheckbox" /></td>
                                <td><input type="checkbox" disabled="disabled" /></td>
                            </tr>
                        </tbody>
                    </table>
                    @Html.HiddenFor(model => model.WallPermission)
                    @Html.ValidationMessageFor(model => model.WallPermission)
                </div>
                <p>
                    <input type="submit" value="@ViewBag.Save" />
                </p>
            </fieldset>
        }
    </div>
</div>
